package com.study.order.proxy.cglib;


import org.springframework.aop.framework.ProxyFactory;

/**
 * @author yuanqiji
 * @date 2022/08/16
 **/
public class Test {
	public static void main(String[] param) {
		test3();
	}

	private static void test3() {
		Proxy proxy = new Proxy();
		proxy.setMethodInterceptor((p, method, args, methodProxy) -> {
			System.out.println("before....");
			return methodProxy.invokeSuper(p, args);//内部无反射,结合代理使用
		});
		proxy.save();
		proxy.save(1);
		proxy.save(1L);
	}

	private static void test2() {
		Proxy proxy = new Proxy();
		Target target = new Target();
		proxy.setMethodInterceptor((o, method, args, methodProxy) -> {
			System.out.println("before....");
			return methodProxy.invoke(target, args);//内部无反射,结合目标使用
		});
		proxy.save();
		proxy.save(1);
		proxy.save(1L);
	}

	private static void test1() {
		Proxy proxy = new Proxy();
		Target target = new Target();
		proxy.setMethodInterceptor((o, method, args, methodProxy) -> {
			System.out.println("before....");
			return method.invoke(target, args);//反射调用
		});
		proxy.save();
		proxy.save(1);
		proxy.save(1L);
	}
}
